/**
 * Model package.
 */
package fr.umlv.m2.ig.model;

import java.util.ArrayList;
import java.util.List;

/**
 * This class defines the builder for the class {@link Line}.
 * 
 * @author Gambouele Bertrand.
 * @author Viravout Alexandre.
 */
public class LineBuilder {

	/**
	 * List of journeys for the {@link Line} object that this builder is
	 * creating.
	 */
	private final List<Journey> journeys;

	/**
	 * The instance of class {@link Line} which will be returned by the builder.
	 */
	private Line line;

	/**
	 * The name attribute for the {@link Line} object which will be created.
	 */
	private String name;

	/**
	 * Creates a {@link LineBuilder} object.
	 */
	public LineBuilder() {
	  this.journeys = new ArrayList<Journey>();
	}

	/**
	 * Sets the name of the object which will be created.
	 * 
	 * @param name the name of the {@link Line} object.
	 */
	public void setName(final String name) {
		this.name = name;
	}

	/**
	 * Adds a journey for the object which will be created.
	 * 
	 * @param origin the start station of the journey.
	 * @param destination the destination of the journey.
	 */
	public void addJourney(final String origin, final String destination) {
		this.journeys.add(new Journey(origin, destination));
	}

	/**
	 * Gets the {@link Line} object created by the builder.
	 * 
	 * @return a new {@link Line} object.
	 */
	public Line getLine() {
		if (this.line == null) {
			this.line = new Line(this.name);

			for (Journey journey : this.journeys) {
				this.line.addJourney(journey);
			}
		}

		return this.line;
	}
}
